<template>
  <div class="wrap">
 <el-date-picker
        :editable="false"
        :picker-options="pickerOptions"
        value-format="yyyy-MM-dd"
        v-model="dateValue"
        type="daterange"
        range-separator="至"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        @change="dateChange">
      </el-date-picker>
      <el-input placeholder="请输入产品名称" style="width:200px;" v-model="productName"></el-input>
      <el-input placeholder="请输入手机号码" style="width:200px;" v-model="phoneNum"></el-input>
       <el-select v-model="typeValue" placeholder="领取类型" class="select" @change="typeChange">
        <el-option
          v-for="item in typeOption"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-button type="primary" icon="el-icon-search" @click="searchClick">搜索</el-button>
    <el-table
      class="table"
      border fit highlight-current-row
      v-loading="loading"
      element-loading-text="加载中"
      element-loading-spinner="el-icon-loading"
      :data="tableData"
      style="width: 100%">
       <el-table-column
          align="center"
          type="index"
          label="编号"
          width="50">
        </el-table-column>
     <el-table-column
          align="center"
          prop="phoneNum"
          label="手机号码">
      </el-table-column>
      <el-table-column
          align="center"
          prop="miScore"
          label="米分">
      </el-table-column>
      <el-table-column
          align="center"
          prop="productName"
          label="产品名称">
      </el-table-column>
      <el-table-column
          align="center"
          label="获取类型">
          <template slot-scope="scope">
            <p>{{typeMap[scope.row.type +'']}}</p>
          </template>
      </el-table-column>
      <el-table-column
          align="center"
          width="200"
          label="时间">
          <template slot-scope="scope">
            {{_mapping.date_format(scope.row.createTime)}}
          </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="pagination"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="query.pageNum"
      :page-size="query.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalNum">
    </el-pagination>
  </div>
</template>
<script>
import _operation from '@/services/operation.js'
import _mapping from '@/utils/_mapping.js'
import { connect } from 'net';
export default {
  data(){
    return {
      loading: false,
      typeMap:{
        '1':'点击产品领取',
        '2':'签到领取',
        '3':'普通红包',
        '4':'现时领取'
      },
      tableData: [{
       
      }],
      tableDataStatistic: [],
      query: {
        pageSize: 30,
        pageNum: 1
      },
      totalNum: 0,
      typeValue:'',
      dateValue: '',
       typeOption: [{
        value: 1,
        label: '点击产品领取'
      }, {
        value:2,
        label: '签到领取'
      }, {
        value:3,
        label: '普通红包'
      }, {
        value:4,
        label: '现时领取'
      }],
      phoneNum:'',
      productName:'',
      type:'',
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      }
    }
  },
  methods: {
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val
      this.getMiScoreList()
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val
     this.getMiScoreList()
    },
    dateChange(val){
      this.getMiScoreList()
     
    },
    typeChange(){
      this.getMiScoreList()
    },
     // 搜索
    searchClick(){
      this.getMiScoreList()
    },
    getMiScoreList(){
      let params = {
         pageNum: this.query.pageNum,
         pageSize: this.query.pageSize,
         startTime: !this.dateValue ? "" : this.dateValue[0],
         endTime: !this.dateValue ? "" : this.dateValue[1],
         phoneNum:this.phoneNum,
         type:this.typeValue,
         productName:this.productName
      }
      _operation.getMiScoreList(params)
      .then(res => {
        this.tableData = res.data.list
        this.totalNum = res.data.total
      })
    }
  },
  created(){
    this.dateValue = [this._mapping.date_format2(new Date()), this._mapping.date_format2(new Date())]
    console.info("fafa",this.dateValue)
    this.getMiScoreList()
  
  }
}
</script>
<style lang="scss" scoped>
.wrap{
  .table{
    margin-top: 10px;
    margin-bottom: 25px;
  }
}
</style>